package cn.edu.jlu.community.disuse;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.Map;

import cn.edu.jlu.community.R;

public class CommunityNotification extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.deprecated_activity_community_notification);

        ListView listView = (ListView) findViewById(R.id.community_notification_listView);
        SimpleAdapter simpleAdapter = new SimpleAdapter(this, DataLoader.notification_list, R.layout.post_list_item,
                new String[]{"title", "update_time", "author", "comment_count"},
                new int[]{R.id.post_title, R.id.post_time,
                        R.id.post_author, R.id.post_comment_number});
        listView.setAdapter(simpleAdapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Map<String, Object> map = DataLoader.notification_list.get(i) ;

                Intent intent = new Intent(CommunityNotification.this , PostContentActivity.class) ;
                intent.putExtra("objID",(String)map.get("objID")) ;
                intent.putExtra("title",(String)map.get("title")) ;
                intent.putExtra("author",(String)map.get("author")) ;
                intent.putExtra("content",(String)map.get("content")) ;

                CommunityNotification.this.startActivity(intent);


            }
        });

        //notification test
        /*
        Button notificationtestbtn = (Button)findViewById(R.id.notificationtestbtn) ;
        notificationtestbtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                AVPush push = new AVPush();

                AVQuery<AVInstallation> query = AVInstallation.getQuery();
                query.whereEqualTo("installationId", AVInstallation.getCurrentInstallation()
                        .getInstallationId());
                Log.i("aaa",AVInstallation.getCurrentInstallation().getInstallationId()) ;  //LOG
                push.setQuery(query);
                push.setChannel("public");

                JSONObject jsonObject = new JSONObject();
                jsonObject.put("action", "com.pushdemo.action");
                jsonObject.put("alert", "hello hello hello ");

                push.setData(jsonObject);
                push.setPushToAndroid(true);
                push.sendInBackground(new SendCallback() {
                    @Override
                    public void done(AVException e) {
                        if( e ==null ) {
                            Toast.makeText(getApplicationContext(), "send successfully", Toast.LENGTH_SHORT).show();
                        }else{
                            Toast.makeText(CommunityNotification.this , e.getMessage() , Toast.LENGTH_LONG).show() ;
                        }
                    }
                });
            }
        });
        */
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_community_notification, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}
